# -*- coding: utf-8 -*-

# Copyright (C) 2011 Dimitri Linten

#This file is part of pyQuiz.
#
#ThunderStrom is free software: you can redistribute it and/or modify
#it under the terms of the GNU Lesser General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#pyQuiz is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public License
#along with pyQuiz..  If not, see <http://www.gnu.org/licenses/>.

"""
Created on Jan 25, 2011

@author: linten
"""
from setupQuiz import *

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.interactive(True)
import xlwt,xlrd


# TODO : consumption for every table : make 3D plot of Room (with coordinates)
# TODO : live update when adding scores
# TODO : prepare different sheets with graphs



def console(variables):
    import os, sys
    # hook thunderstorm tree in path
    quiz_dir = os.path.dirname(os.path.realpath(__file__))
    sys.path.insert(0, quiz_dir)

    # Change the current directory to the one specified as argument
    # This allow drag and drop start on windows
    if len(sys.argv) == 2:
        os.chdir(sys.argv[1])

    init_message = """Welcome in pyQuiz
Copyright (C) 2011  Dimitri Linten
This program comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute
it under certain
conditions
"""
    
    plt_info = "Using -%s- matplotlib backend" % matplotlib.get_backend()
    
    try:
        from IPython.Shell import IPShellEmbed
        ipshell = IPShellEmbed(exit_msg='Thanks for using pyQuiz')
        return  (ipshell,
                 init_message + plt_info + " and -IPython shell-")
        
    except ImportError:
        import code
        import rlcompleter
        import readline
        readline.parse_and_bind("tab: complete")
        print init_message
        shell = code.InteractiveConsole(variables)
        return (shell.interact,
                init_message + plt_info +" and -Interactive Console-")



if __name__=="__main__":
    

    prompt, message = console(locals())
    prompt(message)

    # Run Ipython  ( like thunderstorm)
    
    # Initiate Quiz with data as tag
    #   Quiz is just a list of tables
    # linked to excel sheet to contantly updated to disck as backup , incase it crashes
    
    # Initiate a Table with name, nr people, attributes, methods that can be done on a table
    
    # Initiate plotting Gui linked to list